home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
general
/
viewers
/
polyview
/
polyvw31.lha
/
Polyview3.1
/
new
/
pvutil.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-23
|
9KB
|
310 lines
/*****************************************************************************
* NCSA Polyview 3.0 *
* *
* Version 3 changes and additions by Marc Andreessen. *
* Version 2 by Brian Calvert. *
* *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* *
* This is BETA release software. As such it may contain software bugs and *
* exhibit inconsistencies. *
* *
* Please send bug reports to polyview@ncsa.uiuc.edu. *
* *
* Copyright (c) 1992 The Board of Trustees of the University of Illinois. *
* *
* Permission to use, copy, and modify this software and its *
* documentation for educational, research, and non-profit purposes is *
* hereby granted, provided that the above copyright notice, the original *
* authors names, and this permission notice appear in all such copies. *
* Any distribution of this software requires the explicit and written *
* authorization of the authors. *
* *
* The University of Illinois makes no representations about the *
* suitability of this software for any purpose. It is provided "as is" *
* without warranty of any kind. *
*****************************************************************************/
/* $Header: /usr3/people/gbourhis/pv3/new/RCS/pvutil.c,v 1.1 92/09/18 10:55:26 marca Exp $ */
#ifdef RCSLOG
$Log: pvutil.c,v $
* Revision 1.1 92/09/18 10:55:26 marca
* Initial revision
*
#endif
#include "pv.h"
int bprintf(state_t * state, char * format, ...)
{
va_list args;
char line[MAXLINELEN];
/* Initialize args to the beginning of the list of arguments. Get */
/* the state record pointer and set format to point to the first */
/* string in the list (the format string). */
va_start(args, format);
/* Print the formatted string and arguments to the status window. */
vsprintf(line, format, args);
GUIsetStatus (line);
/* Print the formatted string and arguments to the transcript, if */
/* there is a transcript file. */
if (state->transcript_fp != NULL)
{
fprintf(state->transcript_fp, "; ");
if (vfprintf(state->transcript_fp, format, args) < 0)
{
printf("SYSTEM ERROR: Transcript vprintf in bprintf.\n");
fflush (stdout);
return ST_ERROR;
}
}
/* Shut down the arguments list. */
va_end(args);
return ST_OKAY;
}
int gprintf(state_t * state, int x, int y, int attr, char * format, ...)
{
va_list args;
char line[MAXLINELEN];
int strw, strh;
/* Initialize args to the beginning of the list of arguments. Get */
/* the state record pointer and set format to point to the first */
/* string in the list (the format string). */
va_start(args, format);
/* Print the formatted string and arguments to the array. */
if (vsprintf(line, format, args) < 0)
{
printf("SYSTEM ERROR: vsprintf in gprintf.\n");
return ST_ERROR;
}
/* Print the formatted string and arguments to the graphics window */
/* using the formatting flags. */
strw = strwidth(line);
strh = getheight();
/* GPR_LEFTJ is the default. */
/* GPR_RIGHTJ means that the string should _end_ at (x,y). */
if (attr & GPR_RIGHTJ)
x -= (strw-1);
/* GPR_CENTERH means that the center of the string should be at x. */
else if (attr & GPR_CENTERH)
x -= strw/2;
/* GPR_BOTTOMJ is the default */
/* GPR_TOPJ means that the top of the string should be at y. */
if (attr & GPR_TOPJ)
y -= (strh-1);
/* GPR_CENTERV means that the vertical center of the string should */
/* be at y. */
else if (attr & GPR_CENTERV)
y -= (strh/2 - 1);
/* Move to the appropriate location and write the string. */
cmov2(x, y);
charstr(line);
/* Underline the text, if requested. */
if (attr & GPR_UNDERL)
{
bgnline();
p2f(x,y-2);
p2f(x+strw, y-2);
endline();
}
/* Shut down the arguments list. */
va_end(args);
return ST_OKAY;
}
int stprintf(state_t * state, char * format, ...)
/* DONE */
/* Prints a string to the status window. */
{
char line[MAXLINELEN];
va_list args;
/* Initialize args to the beginning of the list of arguments. Get */
/* the state record pointer and set format to point to the first */
/* string in the list (the format string). */
va_start(args, format);
/* If there is no status window, print the message to stdout. */
if (state->status == NULL)
{
/* Print the formatted string and arguments to stdout. */
bprintf(state, format, args);
}
else
{
/* Copy the string to the status window. */
vsprintf(line, format, args);
GUIsetStatus (line);
}
/* Shut down the arguments list. */
va_end(args);
return ST_OKAY;
}
/* Copies "source" to "dest", substituting the value of "new" for all */
/* occurrences of the value "old". Assumes sizeof(dest) > strlen(source)- */
/* strlen(old)+strlen(new). Always returns the value of dest. */
char *strsub(char *dest, char *source, char *old, char *new)
{
char *start, *next;
/* Initialize the pointers to the beginning of their buffers. */
start = source;
*dest = '\0';
/* Keep copying as long as there are matches. */
while (next = strstr(start, old))
{
/* Copy the part of the source that was skipped over. */
strncat(dest, start, (size_t) (next-start));
/* Substitute the new string. */
strcat(dest, new);
/* Change the starting point of our search. */
start = next + strlen(old);
}
/* Append the rest of the source. */
strcat(dest, start);
return dest;
}
char *substitute(char *dest, char *source, char *pattern, char *format, ...)
{
char line[MAXLINELEN];
va_list args;
/* Initialize args to the beginning of the list of arguments. Get */
/* the state record pointer and set format to point to the first */
/* string in the list (the format string). */
va_start(args, format);
/* Print the formatted string and arguments to stdout. */
if (vsprintf(line, format, args) < 0)
{
printf("SYSTEM ERROR: vsprintf in strsub.\n");
return dest;
}
/* Substitute the formatted string into the source and return it */
/* in dest. */
strsub(dest, source, pattern, line);
/* Shut down the arguments list. */
va_end(args);
return dest;
}
int strwcmp(char *wildstr, char *str)
{
while ( (*wildstr != '\0') && (*str != '\0') && (*wildstr == *str) )
{
wildstr++;
str++;
}
if (*wildstr == '*')
return 0;
else
return (*wildstr - *str);
}
/* COORDINATE CONVERSION ROUTINES: */
float facos2(float x, float r)
{
return facos(x/r);
}
float fasin2(float y, float r)
{
return (fasin(y/r));
}
void cart_to_sphere(float x, float y, float z, float *rho,
float *theta, float *phi)
{
*rho = fhypot(x, fhypot(y, z));
*theta = fatan2(y, x);
*phi = facos2(z, *rho);
return;
}
void sphere_to_cart(float rho, float theta, float phi, float *x, float *y,
float *z)
{
*x = rho * fcos(theta) * fsin(phi);
*y = rho * fsin(theta) * fsin(phi);
*z = rho * fcos(phi);
return;
}
/* Returns a pointer to an array composed of the coordinates. */
float *p3f (float x, float y, float z)
{
float vertex[3];
vertex[0] = x;
vertex[1] = y;
vertex[2] = z;
return vertex;
}
void p2i(long x, long y)
{
long vector[2];
/* Copy the coordinates into an array so that we can call v2i. */
vector[0] = x;
vector[1] = y;
/* Tell the graphics pipeline to use this vertex. */
v2i(vector);
}
void p2f(float x, float y)
{
float vector[2];
/* Copy the coordinates into an array so that we can call v2i. */
vector[0] = x;
vector[1] = y;
/* Tell the graphics pipeline to use this vertex. */
v2f(vector);
}